package com.spyu.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * cron表达式工具类
 *
 * @author spyu
 * @date 2023-03-08
 */
public final class CronUtils {

    public static final String TIME_POINT_CRON = "ss mm HH dd MM ? yyyy";

    /**
     * 转换时间为cron表达式
     * @param ldt
     * @param cronTemplate
     * @return
     */
    public static String convertStrToCron(LocalDateTime ldt, String cronTemplate) {
        String cronExpression = ldt.format(DateTimeFormatter.ofPattern(cronTemplate));
        return cronExpression;
    }

    /**
     * 转换时间点为cron表达式
     * @param ldt
     * @return
     */
    public static String convertTimePointToCron(LocalDateTime ldt) {
        String cronExpression = ldt.format(DateTimeFormatter.ofPattern(TIME_POINT_CRON));
        return cronExpression;
    }
}
